package top.suven.base.http.admin.config.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.suven.base.core.mybatis.PageData;
import top.suven.base.http.admin.config.dao.MqFailInfoWebDao;
import top.suven.base.http.admin.config.model.MqFailInfo;
import top.suven.base.http.admin.config.service.MqFailInfoWebService;
import top.suven.base.http.admin.config.vo.response.MqFailInfoResponseVo;
import top.suven.base.util.utilize.BeanUtil;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Title: MqFailInfoWebServiceImpl.java
 * @Description: MQ消费失败信息的业务处理服务类
 * @author lixiangling
 * @date   2018/09/06 18:49:45
 * @version V1.0.0
 * ----------------------------------------------------------------------------
 *  modifyer    modifyTime                 comment
 *
 * ----------------------------------------------------------------------------
 *
 */
@Component("mqFailInfoWebService")
public class MqFailInfoWebServiceImpl implements MqFailInfoWebService {
    private final static Logger logger = LoggerFactory.getLogger(MqFailInfoWebServiceImpl.class);
    @Autowired
    private MqFailInfoWebDao mqFailInfoWebDao;
    /**
     * @Title: 获取MQ消费失败信息分页信息
     * @Description:
     * @param mqFailInfo @{Link MqFailInfo}
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/09/06 18:49:45
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    public PageData<MqFailInfoResponseVo> getMqFailInfoPage(MqFailInfo mqFailInfo, int start, int pageSize){
        int count = mqFailInfoWebDao.countEntity(mqFailInfo);
        if(count == 0){
            return new PageData<MqFailInfoResponseVo>(Collections.EMPTY_LIST,count);
        }
        List<MqFailInfo> mqFailInfoList = mqFailInfoWebDao.findPageEntity(mqFailInfo, start, pageSize);
        if(mqFailInfoList == null || mqFailInfoList.isEmpty()){
            return new PageData<MqFailInfoResponseVo>(Collections.EMPTY_LIST,count);
        }
        List<MqFailInfoResponseVo> mqFailInfoResponseList = mqFailInfoList.stream().map(mqFailInfoResponse -> {
            MqFailInfoResponseVo mqFailInfoResponseVo = new MqFailInfoResponseVo();
            BeanUtil.copyProperties(mqFailInfoResponse, mqFailInfoResponseVo);
            return mqFailInfoResponseVo;
        }).collect(Collectors.toList());
        return new PageData<MqFailInfoResponseVo>(mqFailInfoResponseList,count);
    }
    /**
     * @Title: 获取MQ消费失败信息列表信息
     * @Description:
     * @param mqFailInfo @{Link MqFailInfo}
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/09/06 18:49:45
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    public List<MqFailInfo> getMqFailInfoList(MqFailInfo mqFailInfo){
        return mqFailInfoWebDao.findEntity(mqFailInfo);
    }
    /**
     * @Title: 获取MQ消费失败信息列表信息
     * @Description:
     * @param ids @{Link List}
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/09/06 18:49:45
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    public List<MqFailInfo> getMqFailInfoListByInit(List<Long> ids){
        return mqFailInfoWebDao.getMqFailInfoListByInit(ids);
    }
    /**
     * @Title: 获取全部待处理的MQ消费失败信息列表信息
     * @Description: 根据标题获取全部待处理的
     * @param topicName @{Link String}
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/09/06 18:49:45
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    @Override
    public List<MqFailInfo> getMqFailInfoListByTopicNameAndInit(String topicName) {
        return mqFailInfoWebDao.getMqFailInfoListByTopicNameAndInit(topicName);
    }

    /**
     * @Title: 新增MQ消费失败信息信息
     * @Description:
     * @param mqFailInfo @{Link MqFailInfo}
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/09/06 18:49:45
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    public void addMqFailInfo(MqFailInfo mqFailInfo){
        mqFailInfoWebDao.createEntity(mqFailInfo);
    }
    /**
    * @Title: 修改MQ消费失败信息信息
    * @Description:
    * @param mqFailInfo @{Link MqFailInfo}
    * @return
    * @throw
    * @author lixiangling
    * @date 2018/09/06 18:49:45
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    public void updMqFailInfo(MqFailInfo mqFailInfo){
        mqFailInfoWebDao.updateEntity(mqFailInfo);
    }
   /**
    * @Title: 获取MQ消费失败信息信息
    * @Description:
    * @param id @{Link Long}
    * @return
    * @throw
    * @author lixiangling
    * @date 2018/09/06 18:49:45
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    public MqFailInfo getMqFailInfo(Long id){
        MqFailInfo mqFailInfo = new MqFailInfo();
        mqFailInfo.setMqFailId(id);
        return mqFailInfoWebDao.retrieveEntity(mqFailInfo);
    }
    /**
     * @Title: 删除MQ消费失败信息信息
     * @Description:
     * @param ids @{Link Long[]}
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/09/06 18:49:45
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    public void del(Long[] ids){
        mqFailInfoWebDao.del(Arrays.asList(ids));
    }
    /**
     * @Title: 取消补偿MQ消费失败信息信息
     * @Description:
     * @param ids @{Link Long[]}
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/09/06 18:49:45
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    public void cancel(Long[] ids,String reason){
        mqFailInfoWebDao.cancel(reason,Arrays.asList(ids));
    }
}